
#include <stdio.h>
#include <stdint.h>
#include <math.h>
#define PI  M_PI

int16_t double2q15(double value)
{
    return value*32768 + (value > 0.0 ? 0.5 : -0.5);
}

static void gen_realCoefAQ15(int n)
{
    double pATable[2*n];
    printf("const q15_t __ALIGNED(4) RealCoefAQ15[%d] ARM_DSP_TABLE_ATTRIBUTE = {\n", n*2);
    for (int i = 0,j=0; i < n; i++)
    {
        pATable[2 * i]     = 0.5 * ( 1.0 - sin (2 * PI / (double) (2 * n) * (double) i));
        pATable[2 * i + 1] = 0.5 * (-1.0 * cos (2 * PI / (double) (2 * n) * (double) i));
        if(j == 0) {
            printf("    ");
        }
        printf("(q15_t)0x%04hx, (q15_t)0x%04hx,", double2q15(pATable[2 * i]), double2q15(pATable[2 * i + 1]));
        if(++j >= 4) {
            printf("\n");
            j = 0;
        } else {
            printf(" ");
        }
    }
    printf("};\n");

    double pBTable[2*n];
    printf("const q15_t __ALIGNED(4) RealCoefBQ15[%d] ARM_DSP_TABLE_ATTRIBUTE = {\n", n*2);
    for (int i = 0,j=0; i < n; i++)
    {
        pBTable[2 * i]     = 0.5 * (1.0 + sin (2 * PI / (double) (2 * n) * (double) i));
        pBTable[2 * i + 1] = 0.5 * (1.0 * cos (2 * PI / (double) (2 * n) * (double) i));
        if(j == 0) {
            printf("    ");
        }
        printf("(q15_t)0x%04hx, (q15_t)0x%04hx,", double2q15(pBTable[2 * i]), double2q15(pBTable[2 * i + 1]));
        if(++j >= 4) {
            printf("\n");
            j = 0;
        } else {
            printf(" ");
        }
    }
    printf("};\n");
}

int main(void)
{
    int n = 64;
    gen_realCoefAQ15(n);

    return 0;
}
